package com.lqd.mall.system.controller;

import com.lqd.mall.basis.response.CommonResult;
import com.lqd.mall.basis.response.Result;
import com.lqd.mall.interaction.basis.vo.TableDataInfoVo;
import com.lqd.mall.interaction.system.SysDictTypeEntity;
import com.lqd.mall.log.annotation.Log;
import com.lqd.mall.log.enums.BusinessType;
import com.lqd.mall.system.SysDictTypeControllerApi;
import com.lqd.mall.system.service.ISysDictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @author 零起点
 * @create 2022-03-21 18:01
 */
@RestController
public class SysDictTypeController implements SysDictTypeControllerApi {

    @Autowired
    ISysDictTypeService sysDictTypeService;

    @Override
    public Result<TableDataInfoVo<SysDictTypeEntity>> list(SysDictTypeEntity entity) {
        TableDataInfoVo<SysDictTypeEntity> infoVo = sysDictTypeService.list(entity);
        return Result.SUCCESS(infoVo);
    }

    @Override
    public Result<SysDictTypeEntity> findSYSDictTypeEntity(Long dictId) {
        SysDictTypeEntity entity = sysDictTypeService.selectById(dictId);
        return Result.SUCCESS(entity);
    }

    @Override
    @Log(title = "对字典数据更新",businessType = BusinessType.UPDATE)
    public CommonResult upateSYSDictTypeEntity(SysDictTypeEntity entity) {
        Optional<Integer> optional = sysDictTypeService.updateEntity(entity, "dict_id");
        return optional.get() > 0 ?CommonResult.SUCCESS():CommonResult.FAIL();
    }
}
